/*是否自动 auto,
  显示个数 visible,
  走动张数 steplen,
  图片滑动速度 speed
  时间 interval
  右按钮 rightbtn,
  左按钮 leftbtn,
  方向类型 type   水平  horizontal 垂直  vertical
*/
;(function(window,$){
  $.fn.scroll=function(options){
    return this.each(function(){
      var move=new scrollC($(this),options);
          move.init();
    })
  };
  $.fn.scroll.defaults={
    auto:false,
    visible:6,
    steplen:6,
    speed:500,
    interval:2000,
    rightbtn:'',
    leftbtn:'',
    type:'vertical'
  };
  function scrollC(selector,options){
    this.selector=selector;
    this.settings=$.extend({},$.fn.scroll.defaults,options);
    this.stor={
      list:this.selector,
      ul:this.selector.children(),
      li:this.selector.children().children()      
    };
    var liwidth=this.stor.li.outerWidth(true),
        liheight=this.stor.li.outerHeight(true),
        listwidth=listheight=ulwidth=ulheight=0,
        floatdir='none';
      this.stepsize=0;
      this.timer;
      this.margindir='marginLeft';

      if(this.settings.type=='horizontal'){
        listwidth=liwidth*this.settings.visible;
        ulwidth='100%';
        listheight=ulheight='auto';
        this.stepsize=liwidth*this.settings.steplen;
        this.margindir='marginLeft';
        floatdir='left';

      }else{
        listheight=liheight*this.settings.visible;
        ulheight='100%';
        listwidth=ulwidth='auto';
        this.stepsize=liheight*this.settings.steplen;
        this.margindir='marginTop';
        floatdir='none';
      }

    this.stor.list.css({
      width:'100%',
      height:listheight,
      overflow:'hidden'
    });
    this.stor.ul.css({
      width:ulwidth,
      height:ulheight
    });
    this.stor.li.css({
      float:floatdir
    })
  };
  scrollC.prototype.init=function(){
    var that=this,
        sets=that.settings;
        sets.rightbtn.bind('click',function(){
          that.play(true);
        })
        sets.leftbtn.bind('click',function(){
          that.play(false);
        })
        if(sets.auto){
          that.selector.parent().hover(function(){
            clearInterval(this.timer);
          },function(){
            this.timer=setInterval(function(){
              that.play(true);
            },sets.interval);
          }).mouseleave();
        }
  }
  scrollC.prototype.play=function(flag){
    if(!this.stor.ul.is(':animated')){
      var dir=flag?-1:1,
          liobj,
          that=this,
          sets=that.settings,
          animatecss={};
          if(sets.type=='horizontal'){
            animatecss = {marginLeft:'+='+ that.stepsize*dir};
          }else{
            animatecss={marginTop:'+='+that.stepsize*dir};

          }
    if(flag){
      liobj=that.refresh().li.slice(0,sets.steplen);
      liobj.clone().appendTo(that.stor.ul);
    }else{
      liobj=that.refresh().li.slice(-sets.steplen);
      liobj.clone().prependTo(that.stor.ul);
      that.stor.ul.css(that.margindir,-that.stepsize);
    }
    that.stor.ul.animate(animatecss,sets.speed,function(){
      if(flag){
        that.stor.ul.css(that.margindir,0)
      }
      liobj.remove();
    })
  }
 }
  scrollC.prototype.refresh=function(){
    this.stor.ul = this.stor.list.children();
    this.stor.li = this.stor.list.children().children();
     return this.stor; 
  };
 
})(window,jQuery);
















 